WooCommerce: Hide Products @ Shop Page

您所在的位置:网站首页 woocommerce remove sorting dropdown WooCommerce: Hide Products @ Shop Page

WooCommerce: Hide Products @ Shop Page

2024-01-24 23:55| 来源: 网络整理| 查看: 265

A client wanted to show only featured products on the shop page. While adding featured products is very easy (just use the WooCommerce shortcode in the page content), it seems very difficult to remove the “default” product loop. Here’s what I did.

WooCommerce Remove Loop at Shop PageWooCommerce Remove Loop at Shop Page – the old way (commenting out core code). Thankfully there’s a better solution! PHP Snippet: Hide All Products @ WooCommerce Shop Page

Please note: “Product Catalog” > “Shop page display” must be set to “Show products” in the WordPress > Appearance > Customizer > WooCommerce admin settings. Following snippet won’t work if you only have product categories @ product page.

To hide the “No products were found matching your selection” message that shows once the Shop page has no products to show, use this other snippet.

/** * @snippet Remove Product Loop @ WooCommerce Shop * @how-to Get CustomizeWoo.com FREE * @author Rodolfo Melogli * @compatible WooCommerce 6 * @community https://businessbloomer.com/club/ */ add_action( 'pre_get_posts', 'bbloomer_remove_products_from_shop_page' ); function bbloomer_remove_products_from_shop_page( $q ) { if ( ! $q->is_main_query() ) return; if ( ! $q->is_post_type_archive() ) return; if ( ! is_admin() && is_shop() ) { $q->set( 'post__in', array(0) ); } remove_action( 'pre_get_posts', 'bbloomer_remove_products_from_shop_page' ); }


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3